export default {
  methods: {
    /**
     * 判断是否包含带中文括号的 label
     * @param {string} label
     */
    needWrapUnit (label) {
      return /（[^）]+）/.test(label)
    },
    /**
     * 分割 label 带中文括号的 label
     * @param {string} label
     * @returns {{name: string, unit: string}} object
     */
    wrapUnit (label) {
      if (!label) return { name: null, unit: '' };

      label = label + '';
      const index = label.indexOf('（')
      if (index < 0) return { name: null, unit: null };

      const m = label.substring(0, index);
      const n = label.substring(index);
      // console.log(label, ' -> ', m, n);
      return {
        name: m,
        unit: n
      }
    }
  }
}
